#include "StdAfx.h"
#include "m4aTags.h"

#include "AtomicParsley_genres.h"

using namespace m4aSharp;

m4aTags::m4aTags(String^ path)
{
	Debug::Assert(String::IsNullOrEmpty(path) == false);
	_path = path;

	_tags = gcnew Dictionary<String^, Object^>(StringComparer::OrdinalIgnoreCase);
}

void m4aTags::Load()
{
	m4aFile^ file = gcnew m4aFile(_path);
	file->Load();

	for each (String^ name in WellKnownTags)
	{
		Object^ o = GetTag(name, file);
		if (o != nullptr)
			_tags->Add(name, o);
	}
}

Object^ m4aTags::GetGenreString(Object^ id)
{
	char* chars = GenreIntToString(Convert::ToInt32(id));
	if (chars != NULL)
		return gcnew String(chars);

	return String::Empty;
}

Object^ m4aTags::GetTag(String^ tag, m4aFile^ file)
{
	if (wellKnownTags->ContainsKey(tag))
	{
		TagRetriever^ retriever = wellKnownTags[tag];
		return retriever->RetrieveTag(file);
	}

	return nullptr;
}